package com.selebash.ast;

import com.selebash.exception.SelebashException;
import com.selebash.runtime.ExecutionContext;
import java.util.ArrayList;
import java.util.List;

/**
 * @author sad
 */
public class CallFunctionAst extends SequenceAst {

    private String functionName;

    public String getFunctionName() {
        return functionName;
    }

    public void setFunctionName(String functionName) {
        this.functionName = functionName;
    }

    @Override
    public void process(ExecutionContext executionContext) {
        AbstractAst astNode = executionContext.getMainScript().getFunctionNode(functionName);
        if (astNode == null) {
            throw new SelebashException("Function '" + functionName + "' is not found in script " + executionContext.getMainScript().getFullName());
        }

        List<AbstractAst> list = new ArrayList<>();
        list.add(astNode);
        runSequenceElements(executionContext, list, null);
    }
}
